<?php

namespace App\Http\Controllers\Home;

use App\Models\Index;
use App\Models\Member;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class IndexController extends BaseController
{
    /**
     * 初始化
     * RegisterController constructor.
     * @param Register $register
     */
    public function __construct(Index $index)
    {
        parent::__construct();
        $this->index = $index;
    }
    /**
     * 用户资料
     */
    public function getIndex()
    {
        $memberinfo = $this->index->getMemberById(session('uid'));
        return view('home/recharge/myinfo',compact('memberinfo'));
    }

    public function postIndex()
    {
        $res = $this->index->member(\request());

        if($res['member']==1){
            return redirect()->back()->with('message', $res['msg'])->withInput();
        }
        if($res['member']==0){
            return redirect()->back()->with('message', $res['msg'])->withInput();
        }
        if($res['member']==2){
            return redirect()->back()->with('message', $res['msg'])->withInput();
        }
        if($res['state']==200){
            return redirect('/');
        }else{
            return redirect('/');
        }
    }
    /**
     * 密码修改
     */
    public function getEdpass()
    {
        return view('home/recharge/edpassword');
    }


    public function postEdpass()
    {
        $res = $this->index->edpass(\request());
        if($res['state']==400){
            return redirect()->back()->with('message', $res['msg'])->withInput();
        }

        if($res['state']==200){
            return redirect('login');
        }

        if($res['state']==0){
            return redirect()->back()->with('message', $res['msg'])->withInput();
        }

    }


    /**
     * 推广排行,按推荐人数从多到少,显示10个
     */
     public function getTgorder(){

         $data = $this->member->getTgOrder();
         //dd($data);
         return view('home.tg.tgorder',compact('data'));

     }

}
